package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.OrdersCourier;
import com.qinggeng.project.system.service.IOrdersCourierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单配送员Controller
 *
 * @author qinggeng
 * @date 2020-06-17
 */
@RestController
@RequestMapping("/system/orderCourier")
public class OrdersCourierController extends BaseController {
    @Autowired
    private IOrdersCourierService ordersCourierService;

    /**
     * 查询订单配送员列表
     */
    @PreAuthorize("@ss.hasPermi('system:courier:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrdersCourier ordersCourier) {
        startPage();
        List<OrdersCourier> list = ordersCourierService.selectOrdersCourierList(ordersCourier);
        return getDataTable(list);
    }

    /**
     * 导出订单配送员列表
     */
    @PreAuthorize("@ss.hasPermi('system:courier:export')")
    @Log(title = "订单配送员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrdersCourier ordersCourier) {
        List<OrdersCourier> list = ordersCourierService.selectOrdersCourierList(ordersCourier);
        ExcelUtil<OrdersCourier> util = new ExcelUtil<OrdersCourier>(OrdersCourier.class);
        return util.exportExcel(list, "courier");
    }

    /**
     * 获取订单配送员详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:courier:query')")
    @GetMapping(value = "/{ordersCourierId}")
    public AjaxResult getInfo(@PathVariable("ordersCourierId") Long ordersCourierId) {
        return AjaxResult.success(ordersCourierService.selectOrdersCourierById(ordersCourierId));
    }

    @GetMapping("/orderRider/{orderId}")
    public AjaxResult orderRider(@PathVariable("orderId") Long orderId) {
        return AjaxResult.success(ordersCourierService.selectOrdersCourierByOrdersId(orderId));
    }

    /**
     * 新增订单配送员
     */
    @PreAuthorize("@ss.hasPermi('system:courier:add')")
    @Log(title = "订单配送员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrdersCourier ordersCourier) {
        return toAjax(ordersCourierService.insertOrdersCourier(ordersCourier));
    }

    /**
     * 修改订单配送员
     */
    @PreAuthorize("@ss.hasPermi('system:courier:edit')")
    @Log(title = "订单配送员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrdersCourier ordersCourier) {
        return toAjax(ordersCourierService.updateOrdersCourier(ordersCourier));
    }

    /**
     * 删除订单配送员
     */
    @PreAuthorize("@ss.hasPermi('system:courier:remove')")
    @Log(title = "订单配送员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ordersCourierIds}")
    public AjaxResult remove(@PathVariable Long[] ordersCourierIds) {
        return toAjax(ordersCourierService.deleteOrdersCourierByIds(ordersCourierIds));
    }
}
